package com.baijia.web.util;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.OrgType;
import com.baijia.common.enums.UserRoleType;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class LoginAndLogoutUtil {

    public static AccountType getByUserRoleType(String userRoleCodeStr, String orgTypeCodeStr) {
        Integer userRoleCode = StringUtils.isEmpty(userRoleCodeStr) ? null : Integer.parseInt(userRoleCodeStr);
        Integer orgTypeCode = StringUtils.isEmpty(orgTypeCodeStr) ? null : Integer.parseInt(orgTypeCodeStr);

        UserRoleType uesrRoleType = UserRoleType.getById(userRoleCode);
        switch (uesrRoleType) {
            case TEACHER:
            case STUDENT:
                return AccountType.USER;
            case ORG_TEACHER:
                return AccountType.ORG_TEACHER;
            case ORG:
                OrgType orgType = OrgType.getOrgTypeByCode(orgTypeCode);
                switch (orgType) {
                    case MAIN:
                        return AccountType.ORG;
                    case SUB:
                        return AccountType.ORG_SUB_ACCT;
                    default:
                        break;
                }
            default:
                break;
        }

        return AccountType.PASSPORT;
    }

}
